<?php
	header('Content-type:text/html;charset=utf-8');
	class JieSuanController extends CommonController{

		public $model;

		public function __init(){
			parent:: __init();

			$this->model=K('Shop_goods_list');
		}

		public function index(){
			// p($_SESSION);
			//购物车中的数据
			
			if (isset($_SESSION['cart'])) {

				$cartData = $_SESSION['cart']['goods'];

				$this->assign('cartData',$cartData);

				$cartTotalPrice = $_SESSION['cart']['total'];

				$this->assign('cartTotalPrice',$cartTotalPrice);

				$cartTotalNum = $_SESSION['cart']['total_rows'];

				$this->assign('cartTotalNum',$cartTotalNum);
			}
			
			// p($goods);

			

			
			$this->dis('jiesuan');
		}

		public function del(){

			$delNum = Q('post.delNum');
			
			// p($delNum);
			$cartData = Cart::getAllData();
		
			if ($cartData && $delNum) {

				//一维数组直接用unset删除就可以了
				//unset可以删除数组
				unset($_SESSION['cart']['goods'][$delNum]);
				$data = array(

					'sid' => $delNum,
					'num' =>0,

					);
				Cart::update($data);

				if (empty($_SESSION['cart']['goods'])) {
					$_SESSION['cart']['total_rows']=0;
					$_SESSION['cart']['total']=0;
				}


			}

			// if (empty($_SESSION['cart']['goods'])) {
			// 	echo json_encode(1);
			// }
			
			
			echo json_encode(0);die;
			
			
			
		}

		public function add(){

			if (IS_POST) {
				$num = Q('post.num');
				$sid = Q('post.sid');
				$data = array(
					'sid' => $sid,
					'num' => $num,
					);
				Cart::update($data); 

				$cartData = Cart::getAllData();
				// p($cartData);
				$tem = array();
				foreach ($cartData['goods'] as $k => $v) {
					$tem['xiaoji'][] = $v['total'];
				}
				$tem['total_rows'] = $cartData['total_rows'];
				$tem['total'] = $cartData['total'];
				
			}
			$this->ajax($tem);
		}

		public function tuichu(){
			session(NULL);
			$this->success('退出成功',go(U("Index/Login/index")));

		}

	}







?>